#include "mainwindow.h"
#include <QApplication>
#include <QTextCodec>
#include <QFont>
#include <QWSServer>
#include "systemfile.h"
#include "ticketdevfile.h"
systemFile *sysInfo;
ticketdevfile *ticketDevInfo;

void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        QString logTime=QDateTime::currentDateTime().toString("yyyyMMdd hh:mm:ss");
        switch (type) {
        //调试信息提示
        case QtDebugMsg:
                txt = QString("Debug: %1--%2").arg(logTime).arg(msg);
                break;
        //一般的warning提示
        case QtWarningMsg:
                txt = QString("Warning: %1--%2").arg(logTime).arg(msg);
        break;
        //严重错误提示
        case QtCriticalMsg:
                txt = QString("Critical: %1--%2").arg(logTime).arg(msg);
        break;
        //致命错误提示
        case QtFatalMsg:
                txt = QString("Fatal: %1--%2").arg(logTime).arg(msg);
                abort();
        }
        QString logname=QDate::currentDate().toString("yyyyMMdd").append(".txt");
        QString delename=QDate::currentDate().addDays(-3).toString("yyyyMMdd").append(".txt");
        QString imageName=QString("rm -rf %1").arg(QDate::currentDate().addDays(-3).toString("yyyyMMdd"));
        QFile outFile(logname);
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
        QFile defile(delename);
        if(defile.exists())
        {
        defile.remove();
        system(imageName.toLocal8Bit().data());
        }
     }


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    qInstallMsgHandler(customMessageHandler);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QWSServer::setCursorVisible(false);
    QFont font;
    font.setPointSize(16);
    font.setFamily("wenquanyi");
    font.setBold(false);
    a.setFont(font);
    sysInfo = new systemFile();
    ticketDevInfo = new ticketdevfile();
    MainWindow w;
    w.showFullScreen();
    
    return a.exec();
}
